#!/bin/bash

##################
. /etc/profile
. ~/.bash_profile
##################
a=( 2014-11-13 2014-11-14 2014-11-15 )

if [ $(hostname) == "publicsyncserver" ];then

	ls -l $0 | grep history_log.sh > /dev/null 2>&1

	if  [ $? -eq 0 ] ;then

	    echo "Donot run this script $0,thanks"
	    exit 1

	fi

fi

#echo ${a[0]}
#echo ${a[1]}

ipaddr=`/sbin/ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'`
appname="ecommerce_${ipaddr}"
applog=/u01/apache-tomcat-7.0.26/logs
localapp=/u03/backuplog/EComercePlatform/log4j

if [ ! -d $localapp ];then

	echo "$localapp folder no  exit"
	exit 1
fi

if [ -f /mnt/backupall/upload/"$appname"_'$logdate'.tgz ];then

        echo  " file "$appname"_'$logdate'.tgz exit already, clear it first"
        exit 3
fi

cd $localapp
#echo "${logdate}"

for ((j=0; j<=`expr "${#a[*]}" - 1`;j++)) ;do

#	find ./  -name "*${a[j]}*" | xargs tar -czvf "$appname"_${a[j]}.tgz 

	if [ ! -f "$appname"_${a[j]}.tgz ];then

		echo " file "$appname"_${a[j]}.tgz no exsit "
		exit 2
	fi
	
#	 if [ -f /mnt/backupall/upload/"$appname"_'$logdate'.tgz ];then

#                echo  " file "$appname"_${a[j]}.tgz exit already"
#                break
        
#        fi

	cp "$appname"_${a[j]}.tgz  /mnt/backupall/upload 

	if [ ! -f /mnt/backupall/upload/"$appname"_${a[j]}.tgz ];then

		echo  " upload "$appname"_${a[j]}.tgz faild"
		exit 4
	fi
done
